package vsvm.data.filter;

import java.util.ArrayList;

import vsvm.data.model.AbstractAttribute;
import vsvm.data.model.AbstractDataModel;

public class DeleteAttributeFilter extends AbstractAttributeFilter {
	private static final long serialVersionUID = 100L;

	public DeleteAttributeFilter() 
	{
		initializeStuff();
		initializeFilters();
	}
	
	public DeleteAttributeFilter(AbstractDataModel model) {
		dataModel = model;
		initializeStuff();
		initializeFilters();
	}
	
	
	@Override
	protected double transform(double val) {
		return 0;
	}


	@Override
	public AbstractDataModel filter() {
		AbstractDataModel dm = dataModel.clone();
		updateDataModel(dm);
		return dm;
	}

	@Override
	public void update() {
		updateDataModel(dataModel);
	}
	
	private void updateDataModel(AbstractDataModel d) {
		ArrayList<double[]> data = new ArrayList<double[]>();
		AbstractAttribute cls = d.getAttribute(d.getClassAttributeIndex());

		for (int j = 0; j < d.getVectorCount(); ++j) {
			double[] a = new double[d.getAttributeCount() - attributes.size()];
			for (int i = 0,k = 0; i < d.getAttributeCount(); ++i) {
				if (!attributes.contains(d.getAttribute(i))) {
					a[k++] = d.getValue(j, i);					
				}
			}
			data.add(a);
		}
		
		ArrayList<AbstractAttribute> at = new ArrayList<AbstractAttribute>();
		for (int i = 0; i < d.getAttributeCount(); ++i)
			if (!attributes.contains(d.getAttribute(i)))
				at.add(d.getAttribute(i));
			
		d.setAttributes(at);
		int cix = 0;
		if (at.contains(cls))
			cix = at.indexOf(cls);
			
		d.setData(data, cix);		
	}

	public void configure() {
		// TODO Auto-generated method stub
		
	}

	public void executeAction(String action) {
		// TODO Auto-generated method stub
		
	}

	public String[] getActions() {
		// TODO Auto-generated method stub
		return new String[0];
	}


	public String getQuickInfo() {
		// TODO Auto-generated method stub
		return null;
	}

}
